package com.atomdayl.domain.therecipe.utils;

import com.google.gson.Gson;

import java.lang.reflect.Type;
import java.util.Date;

/**
 * Created by David on 2016/6/5.
 */
public class GsonHelper {

    private static Gson mInstance;

    public static Gson getInstance() {
        if (mInstance == null) {
            mInstance = new Gson();
        }
        return mInstance;
    }

    public void setGson(Gson gson) {
        this.mInstance = gson;
    }

    public static <T> T getByJson(String jsonStr, Type dataType) {
        if (!jsonStr.isEmpty())
            return getInstance().fromJson(jsonStr, dataType);
        else
            return null;
    }
}
